package com.jiayang.hhotel.presenter;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.bean.Constant;
import com.jiayang.hhotel.bean.InfoModel;
import com.jiayang.hhotel.net.Api;
import com.jiayang.hhotel.ui.AddedSpecialRoomStateActivity;
import com.jiayang.hhotel.util.CommonUtil;
import com.jiayang.hhotel.util.ToastUtil;

import cn.droidlover.xdroidmvp.mvp.XPresent;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.NetError;
import cn.droidlover.xdroidmvp.net.XApi;

/**
 * Created by Administrator on 2017/6/6 0006.
 * 添加特殊房态页面逻辑类
 */

public class AddedSpecialRoomStatePresenter extends XPresent<AddedSpecialRoomStateActivity> {
    /**
     * 保存特殊房态
     * @param mpLanguage 语言
     * @param mpOperation 1 新建；3 取消；5 释放
     * @param mpRoom 房号
     * @param mpRoomReason 原因类型编码
     * @param mpBeginDate 开始日期 格式：2017-05-18
     * @param mpBeginTime 开始时间 格式：08:02:02
     * @param mpEndDate 结束日期 格式：2017-05-18
     * @param mpEndTime 结束时间 格式：08:02:02
     */
    public void cancel(int mpLanguage, final int mpOperation,String mpRoom,String mpRoomReason,String mpBeginDate
                       ,String mpBeginTime,String mpEndDate,String mpEndTime){
        Api.getHomeSer().SpecialRoomSave(Constant.PHONE,mpLanguage,mpOperation,-1,mpRoom,mpRoomReason,mpBeginDate,
                mpBeginTime,mpEndDate,mpEndTime)
                .compose(XApi.<InfoModel>getApiTransformer())
                .compose(XApi.<InfoModel>getScheduler())
                .compose(getV().<InfoModel>bindToLifecycle())
                .subscribe(new ApiSubscriber<InfoModel>() {
                    @Override
                    protected void onFail(NetError error) {
                        CommonUtil.dismissProgressDialog(getV());
                        ToastUtil.Toast(getV().getString(R.string.net_error),getV());
                    }

                    @Override
                    public void onNext(InfoModel Model) {
                        CommonUtil.dismissProgressDialog(getV());
                        switch (Model.getState()){
                            case 9://请求成功
                                ToastUtil.Toast(getV().getString(R.string.already_submit),getV());
                                break;
                            case -1://失败
                                ToastUtil.Toast(getV().getString(R.string.error_code)+Model.getState()+getV().getString(R.string.space)+getV().getString(R.string.service_error_contract_manager),getV());
                                break;
                        }
                    }
                });
    }
}
